// Vector3 class built mostly from the Vector2 class example code in book appendix

#include <cmath>
#include "Vector3.h"

Vector3::Vector3()
{
    x = 0.0;
    y = 0.0;
    z = 0.0;
}

Vector3::Vector3(float dx,float dy,float dz)
{
    x = dx;
    y = dy;
    z = dz;
}

Vector3::Vector3(Vector3& vector)
{
    x = vector.getX();
    y = vector.getY();
    z = vector.getZ();
}

void Vector3::set(Vector3& vector)
{
    x = vector.getX();
    y = vector.getY();
    z = vector.getZ();
}

void Vector3::set(float dx,float dy,float dz)
{
    x = dx;
    y = dy;
    z = dz;
}

void Vector3::setX(float dx)
{
    x = dx;
}

void Vector3::setY(float dy)
{
    y = dy;
}

void Vector3::setZ(float dz)
{
    z = dz;
}

float Vector3::getX()
{
    return x;
}

float Vector3::getY()
{
    return y;
}

float Vector3::getZ()
{
    return z;
}

float Vector3::dotProd(Vector3& vector)
{
    float dot = (x * vector.getX()) + (y * vector.getY()) +
                (z * vector.getZ());
    return dot;
}

Vector3& Vector3::crossProd(Vector3& vector)
{
    float i = (y * vector.getZ()) - (z * vector.getY());
    float j = (x * vector.getZ()) - (z * vector.getX());
    float k = (x * vector.getY()) - (y * vector.getX());

    static Vector3 cross(i,-j,k);
    return cross;
}

void Vector3::normalize()
{
    float length = sqrt((x*x)+(y*y)+(z*z));

    x = x / length;
    y = y / length;
    z = z / length;
}

